﻿/********************************************************************************/
/* 	stage.d																		*/
/*------------------------------------------------------------------------------*/
/*	製作		（　゜ワ゜）ノ　／　松久貫太									*/
/*	製作開始　	2007/09/16														*/
/*	MAIL		omega@personal.email.ne.jp										*/
/*	URL		http://nagoya.cool.ne.jp/o_mega										*/
/*																				*/
/*	このソースは「やらわかライセンス」の元で配布されています。					*/
/*-更新履歴---------------------------------------------------------------------*/
/*	2007/--/--																	*/
/*-その他-----------------------------------------------------------------------*/
/*	なし																		*/
/********************************************************************************/

/* ライブラリのインポート *******************************************************/
private import hell2;		// dHell2ライブラリ
private import screen;
private import player;
private import shot;
private import state;
private import enemy;
private import vector;
private import effect;
private import keypad;
private import actor;

private import std.math;

private import defines;

/* GameMain *********************************************************************/
/*	ゲーム本体の状態															*/
/********************************************************************************/

class Stage{
private:
	enum STAGESTATE{
		NONE,
		START,
		PLAYING,
		ENDRESULT,
		COURSESELECT,
	}
	
	static int START_NOCOUNT = 180;
	
	STAGESTATE stagestate;
	int timer;
	int no_count_timer;
	
	GameMain gamemain;
	
public:
	
	this(GameMain gamemain){
		this.gamemain = gamemain;
		stagestate = STAGESTATE.START;
		timer = 0;
		no_count_timer = START_NOCOUNT;
	}
	
	void move(){
		timer++;
		if(no_count_timer > 0) no_count_timer--;
		
		switch(stagestate){
			case STAGESTATE.START:
				if(no_count_timer <= 0){
					stagestate = STAGESTATE.PLAYING;
					timer = 0;
				}
				break;
			case STAGESTATE.PLAYING:
				checkClear();
				generateEnemy();
				break;
			case STAGESTATE.ENDRESULT:
				break;
			case STAGESTATE.COURSESELECT:
				break;
			default:
				break;
		}
	}
	
	void generateEnemy(){
		if(timer % 2 == 1 && (timer - 150) % 150 < (timer / 150 + 1) * 5 && timer > 0)
		//if(timer % 2 == 1 && (timer - 150) % 150 < (timer / 150 + 1) * 5 && timer > 150)
		{
			double ex = 0;
			double ey = 0;
			while(std.math.abs(ex) < CHAR_X_ABSMAX * 1.5 && std.math.abs(ey) < CHAR_Y_ABSMAX * 1.5)
			{
				ex = Hell_randInt(-cast(int)CHAR_X_ABSMAX * 2 , cast(int)CHAR_X_ABSMAX * 2);
				ey = Hell_randInt(-cast(int)CHAR_Y_ABSMAX * 2 , cast(int)CHAR_Y_ABSMAX * 2);
			}
			
			gamemain.enemyactor.add(
				new Vec3(ex,ey,CHAR_Z_SURFACE),
				new Vec3( Hell_randInt(-100,100) / 2000.0 ,
							Hell_randInt(-100,100) / 2000.0 ,
							0.0 ) ,
				new EnemySpec());
		}
	}
	
	
	void drawBlur(){
		Hell_setAlpha(HELL_ALPHA_PRODUCT);
		Hell_drawRect(0,0,getScreenWidth(),getScreenHeight(), 0, 0, 128,160,240,255);
//		Hell_drawRect(0,0,getScreenWidth(),getScreenHeight(), 0, 0, 248, 208,192,255);
	}
	
	void drawBack(){
		glPushMatrix();
		{
			glTranslatef(0,0,CHAR_Z_SURFACE);
			glScalef(CHAR_Z_SURFACE,CHAR_Z_SURFACE,CHAR_Z_SURFACE * 2);
			glColor4f(0.4, 0.4 , 0.4 , 0.2);
			CubeShape.drawWire();
		}
		glPopMatrix();
		
		// 床グリッド
		for(double x= -CHAR_X_ABSMAX ; x <= CHAR_X_ABSMAX ; x += 2.5)
			{
			for(double y = -CHAR_Y_ABSMAX ; y <= CHAR_Y_ABSMAX ; y += 2.5)
			{
				glPushMatrix();
				glTranslatef(x,y,CHAR_Z_SURFACE);
				glScalef(2,2,0);
				glColor4f(0.5 , 0.5 , 0.5 , 0.2);
				SquareShape.drawWire();
				glPopMatrix();
			}
		}
	}
	
	void draw(){
		switch(stagestate){
			case STAGESTATE.START:
				break;
			default:
				break;
		}
	}
	
	bool isTimeDecrease(){
		switch(stagestate){
			case STAGESTATE.START:
				return false;
				break;
			case STAGESTATE.PLAYING:
				return no_count_timer > 0;
				break;
			case STAGESTATE.ENDRESULT:
				return false;
				break;
			case STAGESTATE.COURSESELECT:
				return no_count_timer > 0;
				break;
			default:
				break;
		}
		return false;
	}
	
	void checkClear(){
	}
}